/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package service;
import dao.MailDao;
import java.util.logging.Level;
import java.util.logging.Logger;
import myUtils.page.Result;
import po.Mail;

/**
 *
 * @author sony
 */
public class MailServiceImpl implements MailService{

     private MailDao mailDao;

    public void addMail(Mail mail) {
        try {
            mailDao.save(mail);
        } catch (Exception ex) {
            Logger.getLogger(MailServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Mail getMail(int id) {
        return mailDao.getMail(id);
    }

    public void deleteMail(int id) {
        try {
            mailDao.deleteMail(id);
        } catch (Exception ex) {
            Logger.getLogger(MailServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public MailDao getMailDao() {
        return mailDao;
    }

    public void setMailDao(MailDao mailDao) {
        this.mailDao = mailDao;
    }

    public Result getReceiveMails(int id,int page) {
        return mailDao.getReceiveMails(id,page);
    }

    public Result getSendMails(int id, int page) {
        return mailDao.getSendBox(id,page);
    }

    public boolean isAuthor(int mailId, int userId) {
        Mail m = mailDao.getMail(mailId);
        return m.getUserByFromId().getId()==userId||m.getUserByToId().getId()==userId;
    }

    public void updateMail(Mail mail) {
        mailDao.updateMail(mail);
    }



}
